﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WPFGeebaClient
{
    /// <summary>
    /// Interaction logic for RegisterWindow.xaml
    /// </summary>
    public partial class RegisterWindow : Window
    {
        private ServerAdapter.WcfGeebaService.User user;
        private ServerAdapter.SAdapter server;

        public RegisterWindow()
        {
            InitializeComponent();
        }

        public RegisterWindow(ServerAdapter.WcfGeebaService.User user, ServerAdapter.SAdapter server)
        {
            InitializeComponent();
            this.user = user;
            this.server = server;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {   
            if (usernameTxt.Text.Length == 0)
            {
                MessageBox.Show("username cannot be empty.");
            }
            else if (passwordBox1.Password.Length == 0)
            {
                MessageBox.Show("password can not be empty.");
            }
            else if (!pbPassConfirm.Password.Equals(passwordBox1.Password))
            {
                MessageBox.Show("passwords do not match.");
            }
            else if (server.serverRegister(usernameTxt.Text, passwordBox1.Password))
            {
                //server.serverLogin(user, usernameTxt.Text, passwordBox1.Password);
                MessageBox.Show("Registered \"" + usernameTxt.Text + "\" successfully.");
                this.Visibility = System.Windows.Visibility.Hidden;
                //login(user);
            }
            else 
            {
                MessageBox.Show("Error in username or password.");
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.Visibility = System.Windows.Visibility.Hidden;

        }

        internal void ClearValues()
        {
            this.passwordBox1.Password = "";
            this.pbPassConfirm.Password = "";
            this.usernameTxt.Text = "";
        }
    }
}
